package ThreadMethod;

public class TestJoin {
    public static void main(String[] args) throws InterruptedException {
        Thread thread1 =new Thread(new Task2());//匿名方法
        Thread thread2 =new Thread(new Task2());//匿名方法
    thread1.start();
    thread2.start();
        for (int i = 0; i <=50; i++) {
            System.out.println(Thread.currentThread().getName()+"-"+i);
            if (i == 20) {
                System.out.println("main执行到20了,执行t1");
                thread1.join();//将t1加入到Main线程中,等待t1执行结束后,main再进行竞争片
            }
        }
    }
}
class Task2 implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i <=50; i++) {
            System.out.println(Thread.currentThread().getName()+"-"+i);
        }
    }
}
